package network

import (
	"encoding/json"
	"time"
)

// Push 推送
func (c *Connection) Push(MsgID int32, value interface{}) error {
	msg := NewMessage(MsgID, 0, int32(time.Now().Unix()))
	var err error

	type Response struct {
		Code    int         `json:"code"`
		Message string      `json:"message"`
		Data    interface{} `json:"content"`
	}
	var r = Response{Code: 1, Message: "success", Data: value}
	msg.Content, err = json.Marshal(r)
	if err != nil {
		return err
	}
	msg.MsgHead.Len = int32(len(msg.Content)) + HeadLen
	return c.Write(msg)
}
